<template>
  <div>
    <h2>随机点名</h2>
    <div class="box">
      <span>名字是：</span>
      <div v-text="i" class="qs">这里显示姓名</div>
    </div>
    <div class="btns">
      <button @click="start" class="start">开始</button>
      <button @click="end" class="end">结束</button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      // youName: "这里显示姓名",
      arr: ["张飞", "黄忠", "赵云", "马超", "关羽", "吕布"],
      id: "",
      i: "这里显示姓名",
    };
  },
  methods: {
    start() {
      this.id = setInterval(() => {
        this.i = this.arr[Math.round(Math.random() * 5)];
      }, 50);
    },
    end() {
      clearInterval(this.id);
      // this.arr.splice(this.i, 1);
    },
  },
};
</script>

<style>
* {
  margin: 0;
  padding: 0;
}

h2 {
  text-align: center;
}

.box {
  width: 600px;
  margin: 50px auto;
  display: flex;
  font-size: 25px;
  line-height: 40px;
}

.qs {
  width: 450px;
  height: 40px;
  color: red;
}

.btns {
  text-align: center;
}

.btns button {
  width: 120px;
  height: 35px;
  margin: 0 50px;
}
</style>+